const data = {
    arr: [1, 2, 3]
};

function defineReactive(obj, key, val) {
    const property = Object.getOwnPropertyDescriptor(obj, key);
    if (property && property.configurable === false) {
        return;
    }
    const getter = property && property.get;
    const setter = property && property.set;
    Object.defineProperty(obj, key, {
        enumerable: true,
        configurable: true,
        get() {
            console.log('取值过程被拦截了');
            const value = getter ? getter.call(obj) : val;
            return value;
        },
        set(newval) {
            console.log(`新的值是${newval}`);
            if (setter) {
                setter.call(obj, newval);
            } else {
                val = newval;
            }
        }
    });
}

defineReactive(data, 'arr', data.arr);
data.arr.push(10);
